//
//  LSZInformationVC.m
//  PartyClassCloud
//
//  Created by 梁素珍 on 2018/8/14.
//  Copyright © 2018年 九酷. All rights reserved.
//

#import "LSZInformationVC.h"
#import "LSZErWeiMaViewController.h"

@interface LSZInformationVC ()<LCDisplayViewControllerDelegate>
@property (strong, nonatomic) UIView *viewFenGe;
@property (strong, nonatomic) NSMutableArray * arrayMutData;
@end

@implementation LSZInformationVC
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.tabBarController.tabBar.hidden=NO;
}
- (void)viewDidLoad {
    [super viewDidLoad];

//    self.navigationItem.title = [_UserM name];
    self.navigationItem.title = @"新郑扶贫";
    //导航颜色和背景
    UINavigationBar * bar = self.navigationController.navigationBar;
    bar.barTintColor = themeColor;
    [self.navigationController.navigationBar setShadowImage:[[UIImage alloc] init]];
    self.navigationController.navigationBar.translucent = YES;
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor],NSFontAttributeName : [UIFont fontWithName:@"Helvetica-Bold" size:22]}];

    self.delegate = self;
    [self setupAllViewController];
    [self setupAllVCData];
    self.view.backgroundColor = [UIColor whiteColor];
    UIView * viewFenGe = [[UIView alloc]initWithFrame:CGRectMake(0, 43+NAVIGATION_BAR_HEIGHT, ScreenWidth, 1)];
    _viewFenGe = viewFenGe;
    viewFenGe.backgroundColor = dividerColor;
    [self.view addSubview:viewFenGe];
    [viewFenGe sendSubviewToBack:self.view];
    /**增加侧滑返回,无其他作用*/
//    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 20, ScreenHeight)];
//    [self.view addSubview:view];
//    [self.view bringSubviewToFront:view];
    NSString *className = [NSString stringWithFormat:@"%@",@"LSZInformationVC"];
    NSString * strDelete = [NSString stringWithFormat:@"%@Login",className];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(goToLogin) name:strDelete object:nil];//删除通知
    
    UIBarButtonItem *rightBarItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"添加"] style:UIBarButtonItemStylePlain target:self action:@selector(clickInformation)];
    self.navigationItem.rightBarButtonItem = rightBarItem;
}
-(void)goToLogin
{
    [LSZPublicClassDataToll goToLogin];
}
- (void)setupAllViewController {
    //下划线
    [self setUpUnderLineEffect:^(BOOL *isUnderLineDelayScroll, CGFloat *underLineH, UIColor *__autoreleasing *underLineColor, BOOL *isUnderLineEqualTitleWidth) {
        // 标题填充模式
        *underLineColor = themeColor;
        *underLineH = 2;
    }];
    // 标题渐变
    // *推荐方式(设置标题渐变)
    [self setUpTitleGradient:^(LCTitleColorGradientStyle *titleColorGradientStyle, UIColor *__autoreleasing *norColor, UIColor *__autoreleasing *selColor) {
        *norColor = RGBColor(51, 51, 51);
        // 设置标题选中颜色
        *selColor = themeColor;
    }];
    // 设置标题字体
    // 推荐方式
    [self setUpTitleEffect:^(UIColor *__autoreleasing *titleScrollViewColor, UIColor *__autoreleasing *norColor, UIColor *__autoreleasing *selColor, UIFont *__autoreleasing *titleFont, CGFloat *titleHeight, CGFloat *titleWidth) {
        // 设置标题字体
        if (ScreenWidth == 414) {
            *titleFont = FONT_(15.5);
        }else
            if (ScreenWidth == 375) {
                *titleFont = FONT_(15);
            }else{
                *titleFont = FONT_(14.5);
            }
    }];
}
- (void)setupAllVCData {
    // 移除之前所有子控制器
    [self.childViewControllers makeObjectsPerformSelector:@selector(removeFromParentViewController)];
    self.arrayMutData = [[NSMutableArray alloc]initWithObjects:@"资讯", nil];
    [LSZRequestDicData informationDirectory:^(BOOL isOk, NSString * str, LSZInformationDirectoryManager * manager) {
        if (isOk == YES) {
            if (manager.mutNameArray.count >0) {
                self.arrayMutData = [[NSMutableArray alloc]initWithArray:manager.mutNameArray];
                for (NSInteger i = 0; i < self.arrayMutData.count; i++) {
                    LSZInformationDirectoryMg * mg = nil;
                    mg = manager.mutMgArray[i];
                    LSZInformationSubinterfaceVC * vc = [[LSZInformationSubinterfaceVC alloc]init];
                    vc.title = self.arrayMutData[i];
                    vc.catalogId = mg.id_id;
                    [self addChildViewController:vc];
                }
            }else{
                LSZInformationSubinterfaceVC * vc = [[LSZInformationSubinterfaceVC alloc]init];
                vc.title = self.arrayMutData[0];
                vc.catalogId= @"";
                [self addChildViewController:vc];
            }
            // 注意：必须先确定子控制器
            [self refreshDisplay];
        }else{
            if ([str isEqualToString:@"重复登录"]) {
                [LSZPublicClassDataToll RepeatLoginInterfaceJump:self.view fromVC:@"LSZInformationVC"];
            }else{
                [LSZPublicClassDataToll initWithAlertKuangView:self.view string:str];
            }
        }
    }];
}
-(void)tabBarContentViewDidSelectItemAtIndex:(NSInteger)index{
    [[NSUserDefaults standardUserDefaults] setInteger:index forKey:@"didSelectAudioChannelAtCid"];
}
///标签头部底部分割线
- (void)viewDidLayoutSubviews {
    [super viewDidLayoutSubviews];
    [_viewFenGe sendSubviewToBack:self.view];
}
-(void)clickInformation
{
    LSZErWeiMaViewController * vc = [[LSZErWeiMaViewController alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
}
@end
